﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SonCa.SocialNetwork.Web.Personals.IPresenters;
using System.ComponentModel.Composition;
using Core.BusinessLogic.Interfaces;
using Core.DataAccess;
using Core.Interfaces;
using Core.Common;

namespace SonCa.SocialNetwork.Web.Personals.Presenters
{
    public class PersonalFriendPresenter
    {
        private IPersonalFriendPresenter _view;

        [Import]
        private IUserSession _userSession;
        [Import]
        private IFriendService _friendService;
        [Import]
        private IAccountService _accountService;
        [Import]
        private ILevelService _levelService;

        public PersonalFriendPresenter()
        {
            MEFManager.Compose(this);
        }

        public void Init(IPersonalFriendPresenter view)
        {            
            _view = view;
            List<Friend> lstFriends = _friendService.GetFriendsByAccountID(_userSession.CurrentUser.AccountID);
            List<int> lstFriendsAccountID = new List<int>();
            foreach (Friend fr in lstFriends)
            {
                if (fr.AccountID == _userSession.CurrentUser.AccountID)
                    lstFriendsAccountID.Add(fr.MyFriendsAccountID);
                else if (fr.MyFriendsAccountID == _userSession.CurrentUser.AccountID)
                    lstFriendsAccountID.Add(fr.AccountID);
            }
            List<Account> lstAccountFriends = _accountService.GetAccountsByAccountIDList(lstFriendsAccountID);
            _view.DisplayListFriend(lstAccountFriends);
        }

        public string GetLevelByLevelID(int levelID)
        {
            return _levelService.GetLevelPathByLevelID(levelID);
        }
    }
}